/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.edit.manager;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Text;

import com.cea.papyrus.diagram.sequence.sedi.figures.ILabeledFigure;


/**
 * Default direct edit locator.
 * 
 * @author frankd@ifi.uio.no
 * 
 * @see com.cea.papyrus.diagram.sequence.sedi.edit.AbstractNamedEditPart
 */
public class LabelLocator implements CellEditorLocator {

	private final ILabeledFigure figure;
	
	public LabelLocator(final ILabeledFigure figure) {
		this.figure = figure;
	}

	public void relocate(final CellEditor celleditor) {
		final Rectangle r = figure.getLabelBounds();
		
		final Text text = (Text)celleditor.getControl();
		org.eclipse.swt.graphics.Rectangle trim = 
			text.computeTrim(r.x, r.y, r.width, r.height);
		
		text.setBounds(trim.x, trim.y, trim.width, trim.height);
	}	
}

